package com.sservice.commonBusiness.controller.web;

import com.sservice.base.entity.dto.BaseResult;
import com.sservice.base.entity.dto.ListResult;
import com.sservice.base.entity.dto.Pagination;
import com.sservice.commonBusiness.e.PLetter;
import com.sservice.commonBusiness.mapper.PLetterMapper;
import com.sservice.commonBusiness.service.PLetterService;
import com.sservice.commonBusiness.vo.PLetterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * Created by byte_su@163.com on 2018/01/12.
 */
@Controller
@RequestMapping("/pLetter/")
public class PLetterPCController {

    @Autowired
    PLetterService pLetterService;
    @Autowired
    PLetterMapper pLetterMapper;


    @RequestMapping(value = "delete/{id}", method = RequestMethod.POST)
    @ResponseBody
    public BaseResult delete( PLetter pLetter) {
        return new BaseResult(true, String.valueOf(pLetterService.deleteByPrimaryKey(pLetter.getId())), 200);
    }

    /**
     *发消息
     * @param pLetter
     * @return
     */
    @RequestMapping(value = "send", method = RequestMethod.POST)
    @ResponseBody
    public BaseResult send(PLetter pLetter) {
        return new BaseResult(true, String.valueOf(pLetterService.insertSelective(pLetter)), 200);
    }
    @RequestMapping(value = "update", method = RequestMethod.POST)
    @ResponseBody
    public BaseResult update(PLetter pLetter) {
        return new BaseResult(true, String.valueOf(pLetterService.updateByPrimaryKeySelective(pLetter)), 200);
    }

    @RequestMapping("detail/{id}")
    @ResponseBody
    public BaseResult detail(PLetter pLetter1) {
        PLetter pLetter = pLetterService.selectByPrimaryKey(pLetter1.getId());
        return new BaseResult(true, pLetter);
    }

    /**
     * 消息列表
     * @param page
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    public ListResult list(PLetterVo page) {
        return pLetterService.page(page);
    }

    @RequestMapping("queryPlain")
    @ResponseBody
    public ListResult queryPlain(PLetterVo page) {
        return pLetterService.pagePlain(page);
    }

    @RequestMapping("queryWithFromUser")
    @ResponseBody
    public ListResult queryWithFromUser(PLetterVo page) {
        List<PLetterVo> list = pLetterService.queryWithFromUser(page);
        ListResult lr = new ListResult(true, list);
        Pagination pagination = new Pagination(page.getPage(), pLetterMapper.count(page), page.getSize());
        lr.setPage(pagination);
        return lr;
    }

    /**
     * 消息统计
     * @param page
     * @return
     */
    @RequestMapping("count")
    @ResponseBody
    public BaseResult count(PLetterVo page) {
        int list = pLetterService.queryCount(page);
        return new BaseResult(true, list);
    }


}
